import router from '../router';
import bus from '../utils/event_bus';
import { getUser, login as loginApi } from './user';
import { getToken, getFundToken } from '../utils/auth';

export function login() {
  return new Promise((resolve) => {
    router.push('/login/mobile');
    bus.$on('login', (data) => {
      resolve(data);
    });
  });
}

export function checkLogin() {
  return new Promise((resolve) => {
    resolve({
      ret: 0,
      status: getToken() ? 1 : 0,
    });
  });
}

export function checkFundLogin() {
  return new Promise((resolve) => {
    resolve({
      ret: 0,
      status: getFundToken() ? 1 : 0,
    });
  });
}

export function closeWebView() {
  return new Promise((resolve) => {
    resolve({
      ret: 0,
    });
  });
}

export function toStockDetail(code, market) {
  console.log('toStockDetail ', {
    code,
    market: appStockMarket,
  });
}

export function shareLink({
  url,
  title,
  message,
} = { }) {
  console.log('shareLink ', {
    img_url: 'https://static.cfzq.com/images/lezhuan_icon_135.png',
    url,
    title,
    message,
  });
}

export function getUserInfo() {
  return getUser();
}

export function fundLogin() {
  return new Promise((resolve) => {
    router.push('/login/fund');
    bus.$on('login', (data) => {
      resolve(data);
    });
  });
}
